<?php
global $type_map;
$type_map['text'] = '的状态';
$type_map['share'] = '的分享';
$type_map['picture'] = '的图片';
$type_map['link'] = '分享的链接';
$type_map['music'] = '分享的音乐';
$type_map['video'] = '分享的视频';

class Like_model extends CI_Model {
	
	public function like($uid,$pid){
		if (!$this->islike($uid, $pid)){
			$data = array(
					'uid'=>$uid,
					'pid'=>$pid
				);
			$this->db->insert('likes',$data);
			return $this->db->insert_id();
		} else {
			return -1;
		}
	}
	
	public function unlike($uid,$pid){
		$this->db->delete('likes', array(
				'pid' => $pid,
				'uid' => $uid,
		));
	}
	
	public function likes_num($pid){
		$this->db->where('pid',$pid);
		$query = $this->db->get('likes');
		return $query->num_rows();
	}
	
	public function islike($uid,$pid){
		$this->db->where('uid',$uid);
		$this->db->where('pid',$pid);
		$query = $this->db->get('likes');
		return $query->num_rows>0;
	}
	
	public function get_like_post($uid){
		$sql = "select * from post where pid in (
				select pid from likes where uid = ?
			) order by posttime desc";
		$query = $this->db->query($sql,array($uid));
		return $query->result_array();
	}
	
}

?>